<!-- 明细账页面 -->
<template>
  <div class="padding" v-loading="loading">
    <!--管理员-->
    <el-card v-if="isAdminOrFinanceHead">
      <el-form
        :inline="true"
        :model="searchCriteria"
        label-width="60px"
        ref="searchCriteria"
        size="mini"
        class="search-form padding-top-sm"
      >
        <el-row>
          <el-col :sm="6" :md="3" :lg="6">
            <el-form-item prop="period" label="会计期间">
              <el-date-picker
                v-model="searchCriteria.period"
                type="monthrange"
                style="width:333px"
                value-format="yyyy-MM"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item prop="startDebitMoney" label="借方金额">
              <el-input
                v-model="searchCriteria.startDebitMoney"
                style="width:150px"
              />
              <span class="margin-lr-sm">-</span>
              <el-input
                v-model="searchCriteria.endDebitMoney"
                style="width:150px"
              />
            </el-form-item>
          </el-col>
          <el-col :sm="6" :md="3" :lg="6">
            <el-form-item prop="financeSubjectNo" label="科目代码">
              <span @dblclick="financeSubjectTree('startFinanceSubjectNo')">
                <el-input
                  v-model="searchCriteria.startFinanceSubjectNo"
                  clearable
                  style="width:150px"
                />
              </span>
              <span class="margin-lr-sm">-</span>
              <span @dblclick="financeSubjectTree('endFinanceSubjectNo')">
                <el-input
                  v-model="searchCriteria.endFinanceSubjectNo"
                  clearable
                  style="width:150px"
                />
              </span>
            </el-form-item>

            <el-form-item prop="startCreditorMoney" label="贷方金额">
              <el-input
                v-model="searchCriteria.startCreditorMoney"
                style="width:150px"
              />
              <span class="margin-lr-sm">-</span>
              <el-input
                v-model="searchCriteria.endCreditorMoney"
                style="width:150px"
              />
            </el-form-item>
          </el-col>
          <el-col :sm="4" :md="6" :lg="4">
            <el-form-item prop="current" label="币种">
              <el-select
                v-model="searchCriteria.current"
                filterable
                clearable
                @change="clearTableData"
              >
                <el-option label="全部" value=""></el-option>
                <el-option
                  v-for="(item, value) in currencyMap"
                  :key="value"
                  :value="value"
                  :label="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="startCurrentRateMoney" label="原币金额">
              <el-input
                v-model="searchCriteria.startCurrentRateMoney"
                style="width:80px"
              />
              <span class="margin-lr-sm">-</span>
              <el-input
                v-model="searchCriteria.endCurrentRateMoney"
                style="width:80px"
              />
            </el-form-item>
          </el-col>
          <el-col :sm="4" :md="6" :lg="4">
            <el-form-item prop="voucherNo" label="凭证号">
              <el-input v-model="searchCriteria.voucherNo" />
            </el-form-item>

            <el-form-item prop="accountTypeId" label="账单类型">
              <el-select
                v-model="searchCriteria.accountTypeId"
                filterable
                clearable
              >
                <el-option
                  v-for="(item, value) in receiveOrPayTypeMap"
                  :key="value"
                  :value="value"
                  :label="m(item)"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="4" :md="6" :lg="4">
            <el-form-item prop="digest" label="摘要">
              <el-input v-model="searchCriteria.digest" />
            </el-form-item>

            <el-form-item label="往来单位">
              <el-select
                v-model="unitIdStr"
                placeholder="请选择往来单位"
                :remote-method="queryUnit"
                clearable
                filterable
                remote
                :style="{ width: '100%' }"
              >
                <el-option-group
                  v-for="(v, i) in unitMap"
                  :key="i"
                  :label="m(v.text)"
                >
                  <el-option
                    v-for="(val, index) in v.children"
                    :key="index"
                    :label="val.text"
                    :value="val.id"
                  ></el-option>
                </el-option-group>
              </el-select>
            </el-form-item>

            <el-button-group>
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-search"
                @click="query()"
                >搜索</el-button
              >
              <el-button size="mini" @click="reset">重置</el-button>
              <el-button type="warning" size="mini" @click="exportTable"
                >导出.xls</el-button
              >
            </el-button-group>
          </el-col>
        </el-row>
      </el-form>
      <span v-show="isShow" style="color:#606266" class="text-xl"
        >请选择会计期间再进行查询</span
      >
      <el-divider></el-divider>
      <!--币种已选择-->
      <div>
        <el-table
          border
          :row-style="tableStyle"
          id="out-eltable"
          :data="tableData"
          class="table-box text-sm"
          style="width:100%"
          v-show="
            searchCriteria.current !== '' && searchCriteria.current !== 'RMB'
          "
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <el-table-column
            prop="financeSubjectNo"
            label="科目"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ financeSubjectSource[scope.row.financeSubjectNo] }}
            </template>
          </el-table-column>
          <el-table-column prop="accountDate" label="日期" width="100">
          </el-table-column>
          <el-table-column prop="voucherNo" label="凭证号" width="70">
            <template slot-scope="scope">
              <div @dblclick="openVoucher(scope)">
                {{ scope.row.voucherNo }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="departList" label="往来单位" show-overflow-tooltip>
            <template slot-scope="scope">
              <template v-if="scope.row.withTheUnitType && scope.row.withTheUnitId">
                <template v-if="scope.row.withTheUnitType == 1">
                  {{userNameMap[scope.row.withTheUnitId]}}
                </template>
                <template v-else-if="scope.row.withTheUnitType == 2">
                  {{customerMap[scope.row.withTheUnitId]}}
                </template>
                <template v-else-if="scope.row.withTheUnitType == 3">
                  {{serveCompanyMap[scope.row.withTheUnitId]}}
                </template>
              </template>
              <template v-else>
                <span v-for="(v, i) in scope.row.departList" :key="i">
                {{ userDeparSource[v] }}
              </span>
              </template>
            </template>
          </el-table-column>
          <el-table-column prop="accountTypeId" label="财务类型" width="100">
            <template slot-scope="scope">
              <!-- {{ scope.row.accountTypeId === 0 ? "应收" : "应付" }} -->
              <span v-if="scope.row.accountTypeId === 0">应收</span>
              <span v-else-if="scope.row.accountTypeId === 1">应付</span>
            </template>
          </el-table-column>
          <el-table-column prop="financeAccountNo" label="财务编号" width="100">
          </el-table-column>
          <el-table-column prop="digest" label="摘要" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="current" label="币别" width="70">
          </el-table-column>
          <el-table-column prop="rate" label="汇率"> </el-table-column>
          <el-table-column label="借方金额">
            <el-table-column prop="currentRateMoney" label="原币">
              <template slot-scope="scope">
                <template
                  v-if="
                    scope.row.currentRateMoney !== null &&
                      scope.row.debitMoney !== null
                  "
                >
                  {{ scope.row.currentRateMoney }}
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="debitMoney" label="本位币">
              <template slot-scope="scope">
                <template
                  v-if="
                    scope.row.debitMoney !== null &&
                      scope.row.currentRateMoney !== null
                  "
                >
                  {{ scope.row.debitMoney }}
                </template>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="贷方金额">
            <el-table-column prop="currentRateMoney" label="原币">
              <template slot-scope="scope">
                <template
                  v-if="
                    scope.row.currentRateMoney !== null &&
                      scope.row.creditorMoney !== null
                  "
                >
                  {{ scope.row.currentRateMoney }}
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="creditorMoney" label="本位币">
              <template slot-scope="scope">
                <template
                  v-if="
                    scope.row.creditorMoney !== null &&
                      scope.row.currentRateMoney !== null
                  "
                >
                  {{ scope.row.creditorMoney }}
                </template>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="余额">
            <el-table-column
              prop="subjectNoAndBalanceTypeName"
              label="余额方向"
              width="70"
            >
              <template slot-scope="scope">
                {{ m(source[scope.row.financeSubjectNo]) }}
              </template>
            </el-table-column>
            <el-table-column prop="originalCurrencyBanlance" label="原币">
            </el-table-column>
            <el-table-column prop="subjectRemainMoney" label="本位币">
            </el-table-column>
          </el-table-column>
        </el-table>
        <!--未选择币种-默认全部-RMB-->
        <el-table
          id="out-eltable"
          border
          :row-style="tableStyle"
          :data="tableData"
          class="table-box text-sm"
          size="mini"
          style="width: 100%"
          v-show="
            searchCriteria.current === 'RMB' || searchCriteria.current === ''
          "
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <el-table-column
            prop="financeSubjectNo"
            label="科目"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ financeSubjectSource[scope.row.financeSubjectNo] }}
            </template>
          </el-table-column>
          <el-table-column prop="accountDate" label="日期" width="100">
          </el-table-column>
          <el-table-column prop="voucherNo" label="凭证号" width="70">
            <template slot-scope="scope">
              <div @dblclick="openVoucher(scope)">
                {{ scope.row.voucherNo }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="departList" label="部门" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-for="(v, i) in scope.row.departList" :key="i">
                {{ userDeparSource[v] }}
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="accountTypeId" label="财务类型" width="100">
            <template slot-scope="scope">
              <!-- {{ scope.row.accountTypeId === 0 ? "应收" : "应付" }} -->
              <span v-if="scope.row.accountTypeId === 0">应收</span>
              <span v-else-if="scope.row.accountTypeId === 1">应付</span>
            </template>
          </el-table-column>
          <el-table-column prop="financeAccountNo" label="财务编号" width="100">
          </el-table-column>
          <el-table-column prop="digest" label="摘要" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="current" label="币别" width="70">
          </el-table-column>
          <el-table-column prop="rate" label="汇率"> </el-table-column>
          <el-table-column prop="currentRateMoney" label="原币金额">
          </el-table-column>
          <el-table-column prop="debitMoney" label="借方金额">
          </el-table-column>
          <el-table-column prop="creditorMoney" label="贷方金额">
          </el-table-column>
          <el-table-column
            prop="subjectNoAndBalanceTypeName"
            label="余额方向"
            width="70"
          >
            <template slot-scope="scope">
              {{ m(source[scope.row.financeSubjectNo]) }}
            </template>
          </el-table-column>
          <el-table-column prop="subjectRemainMoney" label="余额">
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <!--普通人员-->
    <el-card v-else>
      <el-form
        :inline="true"
        :model="searchCriteria"
        label-width="60px"
        ref="searchCriteria"
        size="mini"
        class="padding-top-sm"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item prop="period" label="会计期间">
              <el-date-picker
                v-model="searchCriteria.period"
                type="monthrange"
                style="width:333px"
                value-format="yyyy-MM"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="startCurrentRateMoney" label="原币金额">
              <el-input
                v-model="searchCriteria.startCurrentRateMoney"
                style="width:150px"
                clearable
              />
              <span class="margin-lr-sm">-</span>
              <el-input
                v-model="searchCriteria.endCurrentRateMoney"
                style="width:150px"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item prop="digest" label="摘要">
              <el-input v-model="searchCriteria.digest" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item prop="departId" label="部门">
              <el-select v-model="searchCriteria.departId" filterable clearable>
                <el-option label="全部" value=""></el-option>
                <el-option
                  v-for="(item, value) in belongGroupMap"
                  :key="value"
                  :value="value"
                  :label="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button-group>
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-search"
                @click="query()"
                >搜索</el-button
              >
              <el-button size="mini" @click="reset">重置</el-button>
              <el-button type="warning" size="mini" @click="exportTable()"
                >导出.xls</el-button
              >
            </el-button-group>
          </el-col>
        </el-row>
      </el-form>
      <span v-show="isShow" style="color:#606266" class="text-xl"
        >请选择会计期间再进行查询</span
      >
      <el-divider></el-divider>
      <el-table
        border
        :row-style="tableStyle"
        id="out-eltable"
        :data="tableData"
        class="table-box text-sm"
        size="mini"
        style="width: 100%"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
      >
        <el-table-column
          prop="financeSubjectNo"
          label="科目"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ financeSubjectSource[scope.row.financeSubjectNo] }}
          </template>
        </el-table-column>
        <el-table-column prop="accountDate" label="日期" width="100">
        </el-table-column>
        <el-table-column prop="voucherNo" label="凭证号" width="70">
          <template slot-scope="scope">
            <div @dblclick="openVoucher(scope)">
              {{ scope.row.voucherNo }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="departList" label="部门" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-for="(v, i) in scope.row.departList" :key="i">
              {{ userDeparSource[v] }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="accountTypeId" label="财务类型" width="100">
          <template slot-scope="scope">
            <!-- {{ scope.row.accountTypeId === 0 ? "应收" : "应付" }} -->
            <span v-if="scope.row.accountTypeId === 0">应收</span>
            <span v-else-if="scope.row.accountTypeId === 1">应付</span>
          </template>
        </el-table-column>
        <el-table-column prop="financeAccountNo" label="财务编号" width="100">
        </el-table-column>
        <el-table-column prop="digest" label="摘要" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="current" label="币别" width="70">
        </el-table-column>
        <el-table-column prop="rate" label="汇率"> </el-table-column>
        <el-table-column prop="currentRateMoney" label="原币金额">
        </el-table-column>
        <el-table-column prop="debitMoney" label="借方金额"> </el-table-column>
        <el-table-column prop="creditorMoney" label="贷方金额">
        </el-table-column>
        <el-table-column
          prop="subjectNoAndBalanceTypeName"
          label="余额方向"
          width="70"
        >
          <template slot-scope="scope">
            {{ m(source[scope.row.financeSubjectNo]) }}
          </template>
        </el-table-column>
        <el-table-column prop="subjectRemainMoney" label="余额">
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog title="请选择科目" :visible.sync="dialogVisible">
      <template>
        <el-tabs v-model="subjectTypeActive" type="card">
          <el-tab-pane
            v-for="(item, index) in subjectTypeMap"
            :key="index"
            :label="m(item)"
          >
            <el-tree
              :data="subjectTypeDataMapJson[index]"
              :props="defaultProps"
              @node-click="handleNodeClick"
            >
            </el-tree>
          </el-tab-pane>
        </el-tabs>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";
import { m } from "@/store/yg/common/local";
import FileSaver from "file-saver";
import XLSX from "xlsx";

export default {
  name: "subsidiaryLedger",
  data() {
    return {
      unitMap: [],
      unitIdStr: null,
      defaultProps: {
        children: "financeSubjectNodes",
        label: "label"
      },
      isAdminOrFinanceHead: false,
      dialogVisible: false,
      isShow: true,
      loading: false,
      searchCriteria: {
        current: "",
        startFinanceSubjectNo: "",
        endFinanceSubjectNo: "",
        period: ""
      },
      tableData: [],
      belongGroupMap: {},
      customerMap: {},
      serveCompanyMap: {},
      userNameMap: {},
      currencyMap: {},
      receiveOrPayTypeMap: {},
      fvResult: {},
      subjectTypeMap: {},
      subjectTypeDataMapJson: {},
      source: {},
      financeSubjectSource: {},
      userDeparSource: {},
      subjectTypeActive: 0,
      clickSubjectNo: ""
    };
  },

  mounted() {
    this.init();
  },

  methods: {

    async queryUnit(query) {
      ajax("queryUnit", { name: query },{
        class: "com.tofba.app.client.finance.FinanceAccountWithTheUnitClient"
      }).then(
        res => {
          this.unitMap = res;
        },
        error => {
          console.log(error);
        }
      );
    },

    m(k) {
      return m(k);
    },

    tableStyle({ row, rowIndex }) {
      if (row.digest === "期初余额") {
        let textStyle = { "font-weight": "bold" };
        return textStyle;
      } else if (row.digest === "本期累计" || row.digest === "本年累计") {
        let rowColor = { "background-color": "#fcf8e3" };
        return rowColor;
      }
    },

    // 跳转凭证
    openVoucher(scope) {
      let voucherNo = scope.row.voucherNo;
      let pid = scope.row.financeVoucherId;
      window.open(
        `#/blank/finance__voucher__view?pid=${pid}&voucherNo=${voucherNo}`
      );
    },

    // 清空表格数据
    clearTableData() {
      this.tableData = [];
      // this.isTableData = false;
    },

    // 双击科目事件
    async financeSubjectTree(rowNum) {
      this.dialogVisible = true;
      this.clickSubjectNo = rowNum;
      ajax("queryFinanceSubject", {}).then(
        res => {
          this.subjectTypeMap = res.subjectTypeMap;
          for (const i in res.subjectTypeDataMapJson) {
            this.sortData(res.subjectTypeDataMapJson[i]);
          }
          this.subjectTypeDataMapJson = res.subjectTypeDataMapJson;
        },
        error => {
          console.log(error);
        }
      );
    },

    handleNodeClick(d, n, l) {
      if (d.financeSubjectNodes) {
        return;
      }
      this.dialogVisible = false;
      const label = d.label;
      const financeSubjectNo = d.label.split(" ")[0];
      if (financeSubjectNo) {
        if (this.clickSubjectNo === "startFinanceSubjectNo") {
          this.searchCriteria.startFinanceSubjectNo = financeSubjectNo;
        } else if (this.clickSubjectNo === "endFinanceSubjectNo") {
          this.searchCriteria.endFinanceSubjectNo = financeSubjectNo;
        }
      }
    },

    sortData(data) {
      for (const tmp of data) {
        tmp.label = tmp.financeSubject.no + " " + tmp.financeSubject.name;
        if (
          Object.prototype.toString.call(tmp.financeSubjectNodes) ===
          "[object Array]"
        ) {
          this.sortData(tmp.financeSubjectNodes);
        }
      }
      return data;
    },

    // 页面初始化
    async init() {
      // 判断是否是科目余额表页面跳转过来的
      if (this.$route.query.financeSubjectNo && this.$route.query.period) {
        this.searchCriteria.startFinanceSubjectNo = this.$route.query.financeSubjectNo;
        this.searchCriteria.period = [
          this.$route.query.period,
          this.$route.query.period
        ];
        this.query();
      }
      let res = await ajax("init", {});
      console.log(res);
      if (!res) {
        this.$message.error("初始化页面信息失败，请刷新重试");
        return;
      }
      // 是否管理员
      this.isAdminOrFinanceHead = res.isAdminOrFinanceHead;
      // 部门下拉
      this.belongGroupMap = res.belongGroupMap;
      this.customerMap = res.customerMap;
      this.serveCompanyMap = res.serveCompanyMap;
      this.userNameMap = res.userNameMap;
      this.currencyMap = res.currencyMap;
      this.receiveOrPayTypeMap = res.receiveOrPayTypeMap;
    },

    // 查询
    query() {
      if (!this.searchCriteria.period) {
        this.$message.error("请选择会计期间再进行查询!");
        return;
      }
      //管理员查询时，四种往来单位类型从同一个字段中解析
      if (this.isAdminOrFinanceHead) {
        let unitIdStr = this.unitIdStr;
        let prefix = null;
        let unitId = null;
        if (unitIdStr) {
          prefix = unitIdStr.split('_')[0];
          unitId = unitIdStr.split('_')[1];
          if (prefix == '部门') {
            this.searchCriteria.departId = unitId;
          } else if (prefix == '员工') {
            this.searchCriteria.userId = unitId;
          } else if (prefix == '客户') {
            this.searchCriteria.customerId = unitId;
          } else if (prefix == '服务商') {
            this.searchCriteria.servicerId = unitId;
          }
        }
      }
      this.isShow = false;
      this.loading = true;
      this.tableData = [];
      const startPeriod = this.searchCriteria.period[0];
      const endPeriod = this.searchCriteria.period[1];
      const startFinanceSubjectNo = this.searchCriteria.startFinanceSubjectNo;
      const endFinanceSubjectNo = this.searchCriteria.endFinanceSubjectNo;
      const current = this.searchCriteria.current;
      const voucherNo = this.searchCriteria.voucherNo;
      const digest = this.searchCriteria.digest;
      const startDebitMoney = this.searchCriteria.startDebitMoney;
      const endDebitMoney = this.searchCriteria.endDebitMoney;
      const startCreditorMoney = this.searchCriteria.startCreditorMoney;
      const endCreditorMoney = this.searchCriteria.endCreditorMoney;
      const departId = this.searchCriteria.departId;
      const customerId = this.searchCriteria.customerId;
      const servicerId = this.searchCriteria.servicerId;
      const userId = this.searchCriteria.userId;
      const accountTypeId = this.searchCriteria.accountTypeId;

      ajax("query", {
        startPeriod,
        endPeriod,
        startFinanceSubjectNo,
        endFinanceSubjectNo,
        current,
        voucherNo,
        digest,
        startDebitMoney,
        endDebitMoney,
        startCreditorMoney,
        endCreditorMoney,
        departId,
        customerId,
        servicerId,
        userId,
        accountTypeId
      }).then(
        res => {
          console.log(res);
          if (res.success) {
            this.loading = false;
          } else {
            this.loading = false;
            return this.$message.error(res.message);
          }
          if (res.data) {
            for (let i of res.data) {
              if (i.financeVoucherDetailMonthStatisticsData !== null) {
                this.tableData.push({
                  financeSubjectNo: i.financeSubjectNo,
                  accountDate: i.monthDay,
                  digest: "期初余额",
                  originalCurrencyBanlance: i.originalCurrencyBalanceMoney,
                  subjectRemainMoney: i.initialBalanceMoney
                });
                for (let k of i.financeVoucherDetailMonthStatisticsData) {
                  for (let j of k.financeVoucherDetails) {
                    this.tableData.push({
                      financeSubjectNo: i.financeSubjectNo,
                      accountDate: j.accountDate,
                      voucherNo: j.voucherNo,
                      departList: j.departList,
                      accountTypeId: j.accountTypeId,
                      financeAccountNo: j.financeAccountNo,
                      digest: j.digest,
                      current: j.current,
                      rate: j.rate,
                      currentRateMoney: j.currentRateMoney,
                      debitMoney: j.debitMoney,
                      currentRateMoney: j.currentRateMoney,
                      creditorMoney: j.creditorMoney,
                      subjectNoAndBalanceTypeName: j.financeAccountNo,
                      originalCurrencyBanlance: j.originalCurrencyBanlance,
                      subjectRemainMoney: j.subjectRemainMoney,
                      financeVoucherId: j.financeVoucherId,
                      withTheUnitType: j.withTheUnitType,
                      withTheUnitId: j.withTheUnitId
                    });
                  }
                  this.tableData.push({
                    financeSubjectNo: i.financeSubjectNo,
                    accountDate: k.lastDay,
                    digest: "本期累计",
                    currentRateMoney: k.totalOriginalDebitMoney,
                    debitMoney: k.totalDebitMoney,
                    currentRateMoney: k.totalOriginalCreditorMoney,
                    creditorMoney: k.totalCreditorMoney,
                    originalCurrencyBanlance:
                      k.financeVoucherDetails[
                        k.financeVoucherDetails.length - 1
                      ].originalCurrencyBanlance,
                    subjectRemainMoney:
                      k.financeVoucherDetails[
                        k.financeVoucherDetails.length - 1
                      ].subjectRemainMoney
                  });
                  this.tableData.push({
                    financeSubjectNo: i.financeSubjectNo,
                    accountDate: k.lastDay,
                    digest: "本年累计",
                    currentRateMoney:
                      k.financeVoucherAccrualStatistics
                        .totalyearOriginalDebitMoney,
                    debitMoney:
                      k.financeVoucherAccrualStatistics.totalYearDebitMoney,
                    currentRateMoney:
                      k.financeVoucherAccrualStatistics
                        .totalYearOriginalCreditorMoney,
                    creditorMoney:
                      k.financeVoucherAccrualStatistics.totalYearCreditorMoney,
                    originalCurrencyBanlance:
                      k.financeVoucherDetails[
                        k.financeVoucherDetails.length - 1
                      ].originalCurrencyBanlance,
                    subjectRemainMoney:
                      k.financeVoucherDetails[
                        k.financeVoucherDetails.length - 1
                      ].subjectRemainMoney
                  });
                }
              } else if (i.financeVoucherDetailMonthStatisticsData === null) {
                this.tableData.push({
                  financeSubjectNo: i.financeSubjectNo,
                  accountDate: i.monthDay,
                  digest: "期初余额",
                  originalCurrencyBanlance: i.originalCurrencyBalanceMoney,
                  subjectRemainMoney: i.initialBalanceMoney
                });
                this.tableData.push({
                  financeSubjectNo: i.financeSubjectNo,
                  accountDate: i.monthLastDay,
                  digest: "本期累计",
                  subjectRemainMoney: i.initialBalanceMoney
                });
                this.tableData.push({
                  financeSubjectNo: i.financeSubjectNo,
                  accountDate: i.monthLastDay,
                  digest: "本年累计",
                  subjectRemainMoney: i.initialBalanceMoney
                });
              }
            }
          }
          console.log("处理后的表格数据>>>", this.tableData);
          this.source = res.subjectNoAndBalanceTypeNameSource;
          this.financeSubjectSource = res.financeSubjectSource;
          this.userDeparSource = res.userDeparSource;
          this.loading = false;
        },
        error => {
          console.log(error);
        }
      );
    },
    // 重置
    reset() {
      location.reload();
    },
    // 导出
    exportTable() {
      /* 从表生成工作簿对象 */
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-eltable"));
      /* 获取二进制字符串作为输出 */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        FileSaver.saveAs(
          //Blob 对象表示一个不可变、原始数据的类文件对象。
          //Blob 表示的不一定是JavaScript原生格式的数据。
          //File 接口基于Blob，继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
          //返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
          new Blob([wbout], { type: "application/octet-stream" }),
          //设置导出文件名称
          "明细账.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    }
  }
};
</script>

<style scoped></style>
